package com.foodmarket.service.impl;
import com.foodmarket.pojo.buyerOrders;
import com.foodmarket.mapper.OrderMapper;
import com.foodmarket.pojo.Orders;
import com.foodmarket.service.OrderService;
import com.foodmarket.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.foodmarket.pojo.buyerOrders;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;


    @Override
    public List<Orders> findAllOrder(int sellerId) {
        List<Orders> orders=orderMapper.findAllFood(sellerId);
        return orders;
    }

    @Override
    public List<buyerOrders> findBuyersOrder(){
        Map<String,Object> map= ThreadLocalUtil.get();
        Integer buyerId=(Integer)map.get("id");
        List<buyerOrders> buyerOrders=orderMapper.findBuyersOrders(buyerId);
        System.out.println(buyerOrders);
        return buyerOrders;
    }

    @Override
    public void add(Orders orders) {
        Map<String,Object> map= ThreadLocalUtil.get();
        System.out.println("ThreadLocal contains: " + map);
        Integer buyerId=(Integer)map.get("id");
        orders.setBuyerId(buyerId);
        orderMapper.addOrder(orders);
    }

    @Override
    public void deleteByBuyerId(Integer buyerId) {

        orderMapper.deleteOrder(buyerId);
    }


}